package com.wen.system.oauth;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import me.zhyd.oauth.config.AuthConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.GitProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 *
 * @author liwen <devinlive@163.com>
 * @version 1.0
 * @since 2023-09-03 19:36
 */
@Configuration
public class OAuthConfig {

//    @Autowired
//    private AlipayProperties alipayProperties;
    @Autowired
    private OAuthProperties properties;

    @Bean
    public AlipayConfig buildAlipayConfig(){

        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("<-- 请填写您的AppId，例如：2019091767145019 -->");
        alipayConfig.setPrivateKey("请填写您的privateKey");
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey("请填写您的alipayPublicKey");
        alipayConfig.setCharset("UTF8");
        alipayConfig.setSignType("RSA2");
//        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
        return alipayConfig;
    }
//    @Bean
    public AuthConfig buildGiteeConfig(){
        String clientId = properties.getProperties("Gitee.clientId");
        return AuthConfig.builder()
                .clientId(properties.getGitee().getClientId())
                .clientSecret(properties.getGitee().getClientSecret())
                .redirectUri(properties.getGitee().getRedirectURI())
                .ignoreCheckState(true)
                .build();
    }
}
